package com.myjava.list;

import java.util.ArrayList;
import java.util.ListIterator;

class Student{
        String name;
        int age;
        Student(String name,int age){
            this.name=name;
            this.age=age;
        }
        public String toString() {
        return "Student[name="+name+",age="+age+"]";
        }
       public boolean equals(Object obj){//方法重写
            Student stu = (Student)obj;//向下转型
            return this.name.equals(stu.name)&&this.age==stu.age;
        }
}
public class ArrayListdemo2 {

    static ArrayList singString(ArrayList list){
        ArrayList n1 = new ArrayList();
        //2.遍历就数组
        ListIterator it = list.listIterator();
        while(it.hasNext()){
            Object o1 = it.next();
            //3.新数组的值与原数组的值进行比较是否包含

            if(!n1.contains(o1)){
                //4.如果不同就加入新数组

                n1.add(o1);
            }
        }
        //System.out.println(n1);
        return n1;
    }
    public static void main(String[] args) {
        ArrayList list = new ArrayList();
        list.add(new Student("小燕子",18));
        list.add(new Student("小马仔",22));
        list.add(new Student("小马仔",22));
        ArrayList nelis = singString(list);
        System.out.println(nelis);


    }
}
